﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using UFIDA.U8.DB;

namespace UFIDA.U8C.AnLianDB.DAL
{

    /// <summary>
    /// 数据访问类:cust_queryReceipt
    /// </summary>
    public partial class cust_queryReceipt
    {
        public cust_queryReceipt()
        { }
        #region  BasicMethod
         


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static bool Add(Model.cust_queryReceipt model, string connstr)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into cust_queryReceipt(");
            strSql.Append("serialid,serialNo,downloadNo,downloadUrl,path,fileid)");
            strSql.Append(" values (");
            strSql.Append("@serialid,@serialNo,@downloadNo,@downloadUrl,@path,@fileid)");
            SqlParameter[] parameters = {
					new SqlParameter("@serialid", SqlDbType.NVarChar,50),
					new SqlParameter("@serialNo", SqlDbType.NVarChar,50),
					new SqlParameter("@downloadNo", SqlDbType.NVarChar,50),
					new SqlParameter("@downloadUrl", SqlDbType.NVarChar,512),
					new SqlParameter("@path", SqlDbType.NVarChar,512),
					new SqlParameter("@fileid", SqlDbType.NVarChar,512)};
            parameters[0].Value = model.serialid;
            parameters[1].Value = model.serialNo;
            parameters[2].Value = model.downloadNo;
            parameters[3].Value = model.downloadUrl;
            parameters[4].Value = model.path;
            parameters[5].Value = model.fileid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), connstr, parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static bool Upd(Model.cust_queryReceipt model, string connstr)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update cust_queryReceipt set ");
            strSql.Append("downloadUrl = @downloadUrl where serialid = @serialid "); 
            SqlParameter[] parameters = {
					new SqlParameter("@serialid", SqlDbType.NVarChar,50), 
					new SqlParameter("@downloadUrl", SqlDbType.NVarChar,512) };
            parameters[0].Value = model.serialid; 
            parameters[1].Value = model.downloadUrl; 

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), connstr, parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
         

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Model.cust_queryReceipt GetModel(string serialid, string connstr)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 serialid,serialNo,downloadNo,downloadUrl,path,fileid from cust_queryReceipt ");
            strSql.Append(" where serialid=@serialid ");
            SqlParameter[] parameters = {
					new SqlParameter("@serialid", SqlDbType.NVarChar,50)			};
            parameters[0].Value = serialid;

            Model.cust_queryReceipt model = new Model.cust_queryReceipt();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), connstr, parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }



        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static bool Exists(string serialid, string connstr)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  1 from cust_queryReceipt ");
            strSql.Append(" where serialid= '"+  serialid +"'"); 

            return DbHelperSQL.Exists(strSql.ToString(), connstr);
        }



      


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Model.cust_queryReceipt DataRowToModel(DataRow row)
        {
            Model.cust_queryReceipt model = new Model.cust_queryReceipt();
            Type examType = typeof(Model.cust_queryReceipt);
            if (row != null)
            {
                DataColumnCollection dc = row.Table.Columns;
                for (int i = 0; i < dc.Count; i++)
                {
                    if (row[dc[i].ColumnName] != null && row[dc[i].ColumnName].ToString() != "")
                    {
                        PropertyInfo piInstance = examType.GetProperty(dc[i].ColumnName);
                        if (piInstance != null)
                        {
                            if (row[dc[i].ColumnName] != DBNull.Value)
                            {
                                piInstance.SetValue(model, Convert.ChangeType(row[dc[i].ColumnName], piInstance.PropertyType), null);
                            }
                            else
                            {
                                piInstance.SetValue(model, null, null);
                            }
                        }
                    }
                }
            } 
            /*
            if (row != null)
            {
                if (row["serialid"] != null)
                {
                    model.serialid = row["serialid"].ToString();
                }
                if (row["serialNo"] != null)
                {
                    model.serialNo = row["serialNo"].ToString();
                }
                if (row["downloadNo"] != null)
                {
                    model.downloadNo = row["downloadNo"].ToString();
                }
                if (row["downloadUrl"] != null)
                {
                    model.downloadUrl = row["downloadUrl"].ToString();
                }
                if (row["path"] != null)
                {
                    model.path = row["path"].ToString();
                }
                if (row["fileid"] != null)
                {
                    model.fileid = row["fileid"].ToString();
                }
            }
             * */
            return model;
        }

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
    /// <summary>
    /// 数据访问类:cust_queryaccdetail
    /// </summary>
    public partial class cust_queryaccdetail
    {
        public cust_queryaccdetail()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(string serialId, string connstr)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from cust_queryaccdetail");
            strSql.Append(" where serialId=@serialId ");
            SqlParameter[] parameters = {
					new SqlParameter("@serialId", SqlDbType.NVarChar,50)			};
            parameters[0].Value = serialId;

            return DbHelperSQL.Exists(strSql.ToString(), connstr, parameters);
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static UFIDA.U8.DB.CommandInfo GetUpdGLFlagCommand(string serialId, string inoid, string iyear, string imonth)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update cust_queryaccdetail set ");
            strSql.Append("glflag=1, inoid = @inoid, iyear = @iyear, imonth = @imonth ");
            strSql.Append(" where serialId=@serialId ");
            SqlParameter[] parameters = {  
					new SqlParameter("@serialId", SqlDbType.NVarChar,50),
                    new SqlParameter("@inoid", SqlDbType.NVarChar,50),
                    new SqlParameter("@iyear", SqlDbType.NVarChar,50),
                    new SqlParameter("@imonth", SqlDbType.NVarChar,50)};
            parameters[0].Value = serialId;
            parameters[1].Value = inoid;
            parameters[2].Value = iyear;
            parameters[3].Value = imonth;
            return new CommandInfo(strSql.ToString(), parameters);
        }

        public static int UpdGLFlagCommand(string serialId , string connstr)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update cust_queryaccdetail set ");
            strSql.Append("glflag=1");
            strSql.Append(" where serialId=@serialId ");
            SqlParameter[] parameters = {  
					new SqlParameter("@serialId", SqlDbType.NVarChar,50) };
            parameters[0].Value = serialId; 
            return DbHelperSQL.ExecuteSql(strSql.ToString(),connstr, parameters);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static bool UpdateGLFlag(string serialId, string connstr)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update cust_queryaccdetail set ");
            strSql.Append("glflag=1");
            strSql.Append(" where serialId=@serialId ");
            SqlParameter[] parameters = {  
					new SqlParameter("@serialId", SqlDbType.NVarChar,50)};
            parameters[0].Value = serialId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), connstr, parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static bool UpdateFileFlag(string serialId, string connstr, int operation)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update cust_queryaccdetail set ");
            strSql.Append("fileflag=@fileflag");
            strSql.Append(" where serialId=@serialId ");
            SqlParameter[] parameters = {  
					new SqlParameter("@serialId", SqlDbType.NVarChar,50),
                    new SqlParameter("@fileflag", SqlDbType.Int,4)};  
            parameters[0].Value = serialId;
            parameters[1].Value = operation;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), connstr, parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static CommandInfo GetAddCommand(queryaccdetailsList model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into cust_queryaccdetail(");
            strSql.Append("bankAcc,accName,oppAccName,oppAccNo,inamt,outamt,balance,transtime,exch,jybz,ctype,cbz,memo,serialId,glflag,inoid,createtime,iyear,imonth,pk,errmsg,cflag)");
            strSql.Append(" values (");
            strSql.Append("@bankAcc,@accName,@oppAccName,@oppAccNo,@inamt,@outamt,@balance,@transtime,@exch,@jybz,@ctype,@cbz,@memo,@serialId,@glflag,@inoid,@createtime,@iyear,@imonth,@pk,@errmsg,@cflag)");
            SqlParameter[] parameters = {
                    new SqlParameter("@bankAcc", SqlDbType.NVarChar,50),
                    new SqlParameter("@accName", SqlDbType.NVarChar,150),
                    new SqlParameter("@oppAccName", SqlDbType.NVarChar,150),
                    new SqlParameter("@oppAccNo", SqlDbType.NVarChar,50),
                    new SqlParameter("@inamt", SqlDbType.Decimal,13),
                    new SqlParameter("@outamt", SqlDbType.Decimal,13),
                    new SqlParameter("@balance", SqlDbType.Decimal,13),
                    new SqlParameter("@transtime", SqlDbType.NVarChar,50), 
                    new SqlParameter("@exch", SqlDbType.NVarChar,50),
                    new SqlParameter("@jybz", SqlDbType.NVarChar,500),
                    new SqlParameter("@ctype", SqlDbType.NVarChar,150),
                    new SqlParameter("@cbz", SqlDbType.NVarChar,150),
                    new SqlParameter("@memo", SqlDbType.NVarChar,50),
                    new SqlParameter("@serialId", SqlDbType.NVarChar,50),
                    new SqlParameter("@glflag", SqlDbType.Int,4),
                    new SqlParameter("@inoid", SqlDbType.VarChar,50),
                    new SqlParameter("@createtime", SqlDbType.DateTime),
                    new SqlParameter("@iyear", SqlDbType.Int,4),
                    new SqlParameter("@imonth", SqlDbType.Int,4),
                    new SqlParameter("@pk", SqlDbType.VarChar,50),
                    new SqlParameter("@errmsg", SqlDbType.VarChar,4000),
                    new SqlParameter("@cflag", SqlDbType.VarChar,50)};
            parameters[0].Value = model.bankAcc;
            parameters[1].Value = model.accName;
            parameters[2].Value = model.oppAccName;
            parameters[3].Value = model.oppAccNo;
            parameters[4].Value = model.inamt;
            parameters[5].Value = model.outamt;
            parameters[6].Value = model.balance;
            parameters[7].Value = model.transtime; 
            parameters[8].Value = model.exch;
            parameters[9].Value = model.jybz;
            parameters[10].Value = model.ctype;
            parameters[11].Value = model.cbz;
            parameters[12].Value = model.memo;
            parameters[13].Value = model.serialId;
            parameters[14].Value = model.glflag;
            parameters[15].Value = model.inoid;
            parameters[16].Value = model.createtime;
            parameters[17].Value = model.iyear;
            parameters[18].Value = model.imonth;
            parameters[19].Value = model.pk;
            parameters[20].Value = model.errmsg;
            parameters[21].Value = model.cflag;

            return new CommandInfo(strSql.ToString(), parameters);
        }
       

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static queryaccdetailsList GetModel(string serialId, string connstr)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 bankAcc,accName,oppAccName,oppAccNo,inamt,outamt,balance,transtime,exch,jybz,ctype,cbz,memo,serialId,glflag,inoid,createtime,iyear,imonth,pk,errmsg,cflag from cust_queryaccdetail ");
            strSql.Append(" where serialId=@serialId ");
            SqlParameter[] parameters = {
                    new SqlParameter("@serialId", SqlDbType.NVarChar,50)            };
            parameters[0].Value = serialId;

            queryaccdetailsList model = new queryaccdetailsList();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), connstr, parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static List<queryaccdetailsList> GetModelWhere(string sWhere, string connstr)
        {
            List<queryaccdetailsList> mlist = new List<queryaccdetailsList>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  bankAcc,accName,oppAccName,oppAccNo,inamt,outamt,balance,transtime,exch,jybz,ctype,cbz,memo,serialId,glflag,inoid,createtime,iyear,imonth,pk,errmsg,cflag from cust_queryaccdetail ");
            strSql.Append(" where 1=1 ");
            if (!string.IsNullOrEmpty(sWhere))
            {
                strSql.Append(sWhere);
            } 
            queryaccdetailsList model = new queryaccdetailsList();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), connstr);
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow  item in ds.Tables[0].Rows)
                {
                    mlist.Add(DataRowToModel(item));    
                }

                return mlist;
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static queryaccdetailsList DataRowToModel(DataRow row)
        {
            queryaccdetailsList model = new queryaccdetailsList();

            Type examType = typeof(queryaccdetailsList);
                if (row != null)
                {
                    DataColumnCollection dc = row.Table.Columns;
                    for (int i = 0; i < dc.Count; i++)
                    {
                        if (row[dc[i].ColumnName] != null && row[dc[i].ColumnName].ToString() != "")
                        {
                            PropertyInfo piInstance = examType.GetProperty(dc[i].ColumnName);
                            if (piInstance != null)
                            {
                                if (row[dc[i].ColumnName] != DBNull.Value)
                                {
                                    piInstance.SetValue(model, Convert.ChangeType( row[dc[i].ColumnName], piInstance.PropertyType), null);
                                }
                                else
                                {
                                    piInstance.SetValue(model, null, null);
                                } 
                            }
                        }
                    }
                } 
            /*
            if (row != null)
            {
                if (row["bankAcc"] != null)
                {
                    model.bankAcc = row["bankAcc"].ToString();
                }
                if (row["bankName"] != null)
                {
                    model.bankName = row["bankName"].ToString();
                }
                if (row["accName"] != null)
                {
                    model.accName = row["accName"].ToString();
                }
                if (row["oppAccName"] != null)
                {
                    model.oppAccName = row["oppAccName"].ToString();
                }
                if (row["oppAccNo"] != null)
                {
                    model.oppAccNo = row["oppAccNo"].ToString();
                }
                if (row["oppAccBank"] != null)
                {
                    model.oppAccBank = row["oppAccBank"].ToString();
                }
                if (row["cdSign"] != null)
                {
                    model.cdSign = row["cdSign"].ToString();
                }
                if (row["amt"] != null && row["amt"].ToString() != "")
                {
                    model.amt = row["amt"].ToString();
                }
                if (row["bal"] != null && row["bal"].ToString() != "")
                {
                    model.bal = row["bal"].ToString();
                }
                if (row["transtime"] != null)
                {
                    model.transTime = row["transtime"].ToString();
                }
                if (row["serialNo"] != null)
                {
                    model.serialNo = row["serialNo"].ToString();
                }
                if (row["curCode"] != null)
                {
                    model.curCode = row["curCode"].ToString();
                }
                if (row["cdSignName"] != null)
                {
                    model.cdSignName = row["cdSignName"].ToString();
                }
                if (row["uses"] != null)
                {
                    model.uses = row["uses"].ToString();
                }
                if (row["abs"] != null)
                {
                    model.abs = row["abs"].ToString();
                }
                if (row["voucherNo"] != null)
                {
                    model.voucherNo = row["voucherNo"].ToString();
                }
                if (row["bifCode"] != null)
                {
                    model.bifCode = row["bifCode"].ToString();
                }
                if (row["bankType"] != null)
                {
                    model.bankType = row["bankType"].ToString();
                }
                if (row["oppBankType"] != null)
                {
                    model.oppBankType = row["oppBankType"].ToString();
                }
                if (row["isForIndividual"] != null)
                {
                    model.isForIndividual = row["isForIndividual"].ToString();
                }
                if (row["serialId"] != null)
                {
                    model.serialId = row["serialId"].ToString();
                }
                if (row["bankserailId"] != null)
                {
                    model.bankSerialId = row["bankserailId"].ToString();
                }
                if (row["groupTrans"] != null)
                {
                    model.groupTrans = row["groupTrans"].ToString();
                }
                if (row["capitalTrans"] != null)
                {
                    model.capitalTrans = row["capitalTrans"].ToString();
                }
                if (row["postScript"] != null)
                {
                    model.postScript = row["postScript"].ToString();
                }
                if (row["cashTfrFlg"] != null)
                {
                    model.cashTfrFlg = row["cashTfrFlg"].ToString();
                }
                if (row["glflag"] != null && row["glflag"].ToString() != "")
                {
                    model.glflag = int.Parse(row["glflag"].ToString());
                }
                if (row["fileflag"] != null && row["fileflag"].ToString() != "")
                {
                    model.fileflag = int.Parse(row["fileflag"].ToString());
                }
          
            }   */
            return model;
        }

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}
